/**
 * 
 */
package cc.rico.tutorial.pubsub;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import cc.rico.tutorial.RabbitMQConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.extern.slf4j.Slf4j;

/**
 * @author rico
 *
 */
@Slf4j
public class EmitLog {
	private static final String EXCHANGE_NAME = "logs";

	/**
	 * @param args
	 * @throws IOException 
	 * @throws TimeoutException 
	 */
	public static void main(String[] args) throws IOException, TimeoutException {
		Connection conn = RabbitMQConnectionUtil.getConnection();
		Channel channel = conn.createChannel();
		channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

		String message = "emit log... ";
		// String exchange, String routingKey, BasicProperties props, byte[] body
		channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
		log.info("Sent.messge = {} ", message);

		RabbitMQConnectionUtil.close(conn, channel);
	}

}
